<?php
/*由bean脚本生成 powerBy--joe*/
namespace app\admin\controller;
use app\common\enum\StoreOpenVipEnum;
use app\common\enum\StoreStatusEnum;
use app\common\bean\StoreBean;
use app\common\manage\StoreManage;
use app\common\bean\ListMap;
use app\common\controller\AdminController;
use app\common\model\StoreModel;
use app\common\utils\ExitJsonUtil;
use Exception;

class Store extends AdminController
{
    public function edit(){
        $id = $this->postParams['id'];
        $field = $this->postParams['field'];
        $value = $this->postParams['value'];
        StoreModel::getInstance()->updateColumn(StoreBean::$id, $id, $field, $value);
        ExitJsonUtil::getInstance()->exitData([]);
    }
	/**
	 * @desc store列表
	 * @return mixed
	 * @throws Exception
	*/
	public function storeList(){
		// TODO: Implement getName() method.
        $listMap = new ListMap();
		$listMap->setData($this->getParams);
		$storeMap = StoreManage::getInstance()->getPaginatorList($listMap);
		$this->assign("storeList",$storeMap->getList());
		$this->assign("currentPage",$storeMap->getCurrentPage());
		$this->assign("totalCount",$storeMap->getTotalCount());
        $this->assign('statusSelect',StoreStatusEnum::getArrayName());
		return $this->fetch();
	}

    /**
     * 审核加盟商家
     * @throws Exception
     */
	public function reviewStore(){
	    $storeBean = new StoreBean();
	    if(request()->isPost()){
            $storeBean->setData($this->postParams);
            $result = StoreManage::getInstance()->reviewStore($storeBean);
            ExitJsonUtil::getInstance()->executeAfterReturning([]);
            if($storeBean->getStatus() == StoreStatusEnum::SUCCESS && $result){
                StoreManage::getInstance()->generateStoreData($storeBean->getId());
            }
        }
        $storeBean->setData($this->getParams);
	    $storeBean = StoreManage::getInstance()->getInfo($storeBean);
	    $this->assign('store',$storeBean->getData());
	    $this->assign('statusSelect',StoreStatusEnum::getArrayName());
        return $this->fetch();
    }

    /** 修改店铺
     * @return mixed
     * @throws Exception
     */
    public function editStore(){
        $storeBean = new StoreBean();
        if(request()->isPost()){
            $storeBean->setData($this->postParams);
            $result = StoreManage::getInstance()->edit($storeBean);
            ExitJsonUtil::getInstance()->exitData($result);
        }
        $storeBean->setData($this->getParams);
        $storeBean = StoreManage::getInstance()->getInfo($storeBean);
        $this->assign('store',$storeBean->getData());
        $this->assign('openVipSelect',StoreOpenVipEnum::getArrayName());
        return $this->fetch();
    }
}